from fastapi import APIRouter, Depends, Request
from sqlalchemy.ext.asyncio import AsyncSession

from config.get_db import get_db
from module_admin.aspect.interface_auth import CheckUserInterfaceAuth
from module_admin.service.login_service import LoginService
from module_stock.entity.vo.stat_position_vo import StatPositionPageQueryModel
from module_stock.service.stat_position_service import StatPositionService
from utils.log_util import logger
from utils.page_util import PageResponseModel
from utils.response_util import ResponseUtil

statPositionController = APIRouter(prefix='/stock/stat_position',
                                   dependencies=[Depends(LoginService.get_current_user)])


@statPositionController.get(
    '/list', response_model=PageResponseModel,
    dependencies=[Depends(CheckUserInterfaceAuth('stock:stat_position:list'))]
)
async def get_stat_position_list(
        request: Request,
        stat_position_page_query: StatPositionPageQueryModel = Depends(StatPositionPageQueryModel.as_query),
        query_db: AsyncSession = Depends(get_db),
):
    # 获取分页数据
    stat_position_page_query_result = await StatPositionService.get_stat_position_list_services(query_db,
                                                                                                stat_position_page_query,
                                                                                                is_page=stat_position_page_query.is_page)
    logger.info('获取成功')

    if stat_position_page_query.is_page:
        return ResponseUtil.success(model_content=stat_position_page_query_result)
    else:
        return ResponseUtil.success(rows=stat_position_page_query_result)
